<?
header ("Content-Type: image/gif");
set_time_limit ( 90); 
if (isset($_POST))
{
  include ("YAxisRotate.php");
}
  
function  upload_file()
{
  if (!is_dir("assets"))
  {
      mkdir ("assets");
  }
   $x=new YAxisRotate();
  $pictures = array(); 
  $total = 0;
  $ratio = NULL;
    for ($i=0;$i<5;$i++) { 
      if (trim($_FILES['uploadedfile']['name'][$i])!="") 
	  { 
	  
	  
	     $uploaded_name = $_FILES['uploadedfile']['name'][$i]; 
	     if ($_FILES['uploadedfile']['size'][$i] < 100000)
		 {
			$newfile = "./assets/". $_FILES['uploadedfile']['name'][$i]; 
			
			$im = @imagecreatefromjpeg ($_FILES['uploadedfile']['tmp_name'][$i]);
			if ($im)
			{
			    if ( imagesx ($im) > 200 || imagesy ($im) > 200 )
				{
				    if (!isset($_POST["a_resize"]) || $_POST["a_resize"] > 200)
					{
				        $x->resize=200; 
						$tmp_rto = imagesx ($im) / imagesy ($im);
						if ($ratio)
						{
						    if ($tmp_rto != $ratio)
							{
								 echo "All files must have the same ratio of width to height. \n";
								 echo $_FILES['uploadedfile']['name'][$i] . " -- \n";
								 echo $_FILES['uploadedfile']['size'][$i] . " bytes -- \n";
								 echo "<font color=red>" . $_FILES['uploadedfile']['type'][$i] . "</font> -- \n"; 
								 exit;
							}
						}
						else
						{
						   $ratio = $tmp_rto;
						}
					}
				}
			}
			else
			{
				 echo "Please only upload JPEG files. \n";
				 echo $_FILES['uploadedfile']['name'][$i] . " -- \n";
				 echo $_FILES['uploadedfile']['size'][$i] . " bytes -- \n";
				 echo "<font color=red>" . $_FILES['uploadedfile']['type'][$i] . "</font> -- \n";
				 exit;
			}
			
			move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$i], $newfile);  
			$pictures[] = $newfile;
			$total += $_FILES['uploadedfile']['size'][$i];
			$j++; 
		 }
		 else
		 {
		     echo "Please limit individual images to 100K for this demonstration. \n";
		     echo $_FILES['uploadedfile']['name'][$i] . " -- \n";
		     echo "<font color=red>" . $_FILES['uploadedfile']['size'][$i] . " bytes</font> -- \n";
		     echo $_FILES['uploadedfile']['type'][$i] . " -- \n";
			 exit;
		 }
      }  
    }  
	
	if ($total > 500000)
	{
        echo "Please limit total image sizes to 500K for this demonstration. \n"; 
        exit;
	}
	
	if (count($pictures)>0)
	{
			
        $x->pictures=$pictures;
		#$x->use_border=true;
		$x->debug= $_POST["debug"]!="" ;
		#$x->use_reflection=true;
		$x->spacing=1;
		#$x->delay=12;
		#$x->pause=120;
		$x->frames_per_turn=6; 
		$x->border_color=0X339933; 
		#$x->bg_color=0XFFCCCC; 
		#$x->palette_width=500;
		#$x->palette_height=600; 
		$x->saveframes=true;
		$x->savepath="../../yenc/f";
		#$x->angle=15; 
		$x->dither=$_POST["dither"]!="";
		$x->process_as_jpeg=$_POST["smooth"]!="";
		
		while (list($a,$b)=each($_POST))
		{
		    if (strpos($a,"a_")!==false)
			{
			    eval ("\$x->" . substr($a,2) . "='" . $b . "';");
			}
		} 
		header('Content-Disposition: attachment; filename="' . $uploaded_name . '.gif"');
		$x->create();
		
	}
	else
	{
	    echo "You must upload at least one picture";
	}
}
upload_file();
?> 